﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;
using Sharp.Portal;
using Sharp.Portal.ExtNet;
using Sharp.Portal.Mvc.List;
using Sharp.Portal.Other;

namespace Sharp.WebBooter.Areas.Platform.Models
{
    [DataHandler("AddUserWindow", "添加", 1)]
    [DataHandler("RemoveUser", "删除", 3)]
    public class UserInRoleModel : ExtSharpList
    {
        public UserInRoleModel()
        {
            this.Feature = ListFeature.MultiSelect | ListFeature.Paging;
            this.ToolbarButtonParameters.Add(new ToolButtonInfo()
            {
                Mode = "AddUserWindow",
                Direct = new ToolButtonInfo.DirectClickAction("AddUserWindow", "Role"),
                Parameters = new List<ToolButtonInfo.Parameter>()
                {
                    new ToolButtonInfo.Parameter("id",
                        "Model.Id", (int) ParameterMode.Value),
                    new ToolButtonInfo.Parameter("refreshGrid", "this.up('grid').ownerGrid.getId()", (int) ParameterMode.Raw)
                }
            });
            this.ToolbarButtonParameters.Add(new ToolButtonInfo()
            {
                Mode = "RemoveUser",
                Direct = new ToolButtonInfo.DirectClickAction("RemoveUser", "Role"),
                Parameters = new List<ToolButtonInfo.Parameter>()
                {
                    new ToolButtonInfo.Parameter("userIds",
                        "App.Grid.getSelectedIds(this.up('grid'))", (int) ParameterMode.Raw),
                    new ToolButtonInfo.Parameter("roleId",
                        "Request.Params[\"Id\"]", (int) ParameterMode.Value),
                    new ToolButtonInfo.Parameter("refreshGrid", "this.up('grid').ownerGrid.getId()", (int) ParameterMode.Raw)
                }
            });
        }

        public string Id { get; set; }

        [Ext.Net.MVC.Column(Text = "用户名", Width = 200)]
        public string UserName { get; set; }
        protected override void InitQueryPanel()
        {
            base.InitQueryPanel();
            this.QueryItems.Add(new QueryItem()
            {
                Name = "Roles[].Id",
                IsHiddenField = true,
                ValueFrom  = QueryItem.ValueFromType.ValueFromRequest ,
                ValueFromName = "Id"
            });


        }
    }
}